package github.kawaiior.yuanchuxiuzhen.common.item.weapon.refine;

import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.world.World;

import javax.annotation.Nullable;
import java.util.List;

public class GreenRainbowSword extends RefineWeaponBase{

    @Override
    public float getAttackDamage(){
        return 7F;
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity entity) {
        CompoundNBT nbt = stack.getOrCreateTag();
        int count = nbt.getInt("count");
        nbt.putInt("count", count+1);
        return super.onLeftClickEntity(stack, player, entity);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
        if (worldIn.isRemote){
            return super.onItemRightClick(worldIn, playerIn, handIn);
        }
        CompoundNBT nbt = playerIn.getHeldItem(handIn).getOrCreateTag();
        int count = nbt.getInt("count");
        if (count>10){
            playerIn.addPotionEffect(new EffectInstance(Effects.SPEED, count * 10));
            playerIn.addPotionEffect(new EffectInstance(Effects.STRENGTH, count * 10));
            nbt.putInt("count", 0);
        }
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

    @Override
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
        CompoundNBT nbt = stack.getOrCreateTag();
        tooltip.add(new StringTextComponent("已收集"+nbt.getInt("count")+"点能量"));
        tooltip.add(new StringTextComponent("右键消耗能量获取增益"));
    }
}
